package org.devgframwork.platform.utils.mutitread;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class SynchronizedTest {

    private static Lock lock = new ReentrantLock();

    private int a = 0;

    public void sayA() {
        synchronized (this) {
            System.out.println("a=" + a++);
        }
        /*lock.lock();
        try {
            Thread.sleep(1000);
            System.out.println("a=" + a++);
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            lock.unlock();
        }*/
    }


    public static void main(String[] args) {
        SynchronizedTest synchronizedTest = new SynchronizedTest();
        for (int i = 0; i < 1000; i++) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    synchronizedTest.sayA();
                }
            }).start();
        }


    }
}
